﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracer
{
    class Triangle
    {      
        private int material;
        private Point3D firstVertex;
        private Point3D secondVertex;
        private Point3D thirdVertex;

        // CONSTRUCTORS
        public Triangle()
        {
            this.material = 0;
            this.firstVertex = new Point3D();
            this.secondVertex = new Point3D();
            this.thirdVertex = new Point3D();
        }

        public Triangle(int material, Point3D firstVertex, Point3D secondVertex, Point3D thirdVertex)
        {
            this.material = material;
            this.firstVertex = firstVertex;
            this.secondVertex = secondVertex;
            this.thirdVertex = thirdVertex;
        }

        // PROPERTIES
        public int Material
        {
            get { return this.material; }
            set { this.material = value; }
        }

        public Point3D FirstVertex
        {
            get { return this.firstVertex; }
            set { this.firstVertex = value; }
        }

        public Point3D SecondVertex
        {
            get { return this.secondVertex; }
            set { this.secondVertex = value; }
        }

        public Point3D ThirdVertex
        {
            get { return this.thirdVertex; }
            set { this.thirdVertex = value; }
        }

        // METHODS
        public Vector CalcNormal()
        {
            Vector v1 = new Vector(secondVertex.X - firstVertex.X, secondVertex.Y - firstVertex.Y, secondVertex.Z - firstVertex.Z);
            Vector v2 = new Vector(thirdVertex.X - firstVertex.X, thirdVertex.Y - firstVertex.Y, thirdVertex.Z - firstVertex.Z);
            Vector v = Vector.CrossProduct(v1,v2);
            return v.Normalize();
        }

    }
}
